<template>
    <div class="order-trend">
        <div class="row">
            <div class="col-md-12">
                <div class="white-box">
                    <div class="row" style="margin-bottom: 10px;">
                        <div class="col-md-6">
                            <label>X日期间隔</label>
                            <input v-model="params.xDelta" class="form-control" type="number"/>
                        </div>
                        <div class="col-md-6">
                            <label>X日期范围</label>
                            <input v-model="params.xRange" class="form-control" type="number"/>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <label>Y日期间隔</label>
                            <input v-model="params.yDelta" class="form-control" type="number"/>
                        </div>
                        <div class="col-md-6">
                            <label>Y日期范围</label>
                            <input v-model="params.yRange" class="form-control" type="number"/>
                        </div>
                    </div>
                    <div class="row" style="margin-top: 10px;">
                        <div class="col-md-12">
                            <button class="btn btn-info pull-right" type="button" @click="fetch">Go!</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="white-box" style="position: relative;">
                    <loading :show="loading"></loading>
                    <chart className="trend"  :x="x" :y="y" title="Order趋势图"></chart>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import Chart from '@/components/widgets/Chart/Chart'
    import Loading from '@/components/widgets/Loading'
    import {queryCurve} from '@/api/stat'
    export default {
        name: "OrderTrend",
        components: {Loading, Chart},
        mounted() {
            this.fetch()
        },
        data() {
            return {
                loading: false,
                y: [],
                x: [],
                params: {
                    xDelta: 3,
                    xRange: 50,
                    yDelta: 7,
                    yRange: 60,
                }
            }
        },
        methods: {
            fetch() {
                this.loading = true
                queryCurve('order_trend', this.params).then( res => {
                    let data = []
                    res.data.titles.forEach( (item, index) => {
                        data.push({
                            'name': item + 'days',
                            'data': res.data.y[index]
                        })
                    } )
                    this.y = data.reverse()
                    this.x = res.data.x
                    this.loading = false
                } ).catch (e => this.loading = false)
            }
        }
    }
</script>

<style scoped>

</style>